package com.ruoyi.jiuzai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jiuzai.domain.Wuzibaofei;
import com.ruoyi.jiuzai.service.IWuzibaofeiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资报废Controller
 * 
 * @author ruoyi
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/jiuzai/wuzibaofei")
public class WuzibaofeiController extends BaseController
{
    @Autowired
    private IWuzibaofeiService wuzibaofeiService;

    /**
     * 查询物资报废列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzibaofei:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wuzibaofei wuzibaofei)
    {
        startPage();
        List<Wuzibaofei> list = wuzibaofeiService.selectWuzibaofeiList(wuzibaofei);
        return getDataTable(list);
    }

    /**
     * 导出物资报废列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzibaofei:export')")
    @Log(title = "物资报废", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wuzibaofei wuzibaofei)
    {
        List<Wuzibaofei> list = wuzibaofeiService.selectWuzibaofeiList(wuzibaofei);
        ExcelUtil<Wuzibaofei> util = new ExcelUtil<Wuzibaofei>(Wuzibaofei.class);
        util.exportExcel(response, list, "物资报废数据");
    }

    /**
     * 获取物资报废详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzibaofei:query')")
    @GetMapping(value = "/{baoId}")
    public AjaxResult getInfo(@PathVariable("baoId") Long baoId)
    {
        return success(wuzibaofeiService.selectWuzibaofeiByBaoId(baoId));
    }

    /**
     * 新增物资报废
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzibaofei:add')")
    @Log(title = "物资报废", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wuzibaofei wuzibaofei)
    {
        int result = wuzibaofeiService.insertWuzibaofei(wuzibaofei);
        if (result > 0) {
            // 假设insertWuzibaofei方法返回的是影响的行数，且wuzibaofei对象的id会被MyBatis自动填充
            return AjaxResult.success("操作成功", wuzibaofei.getBaoId());
        }
        return AjaxResult.error("操作失败");
    }
    /**
     * 修改物资报废
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzibaofei:edit')")
    @Log(title = "物资报废", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wuzibaofei wuzibaofei)
    {
        return toAjax(wuzibaofeiService.updateWuzibaofei(wuzibaofei));
    }

    /**
     * 删除物资报废
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzibaofei:remove')")
    @Log(title = "物资报废", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baoIds}")
    public AjaxResult remove(@PathVariable Long[] baoIds)
    {
        return toAjax(wuzibaofeiService.deleteWuzibaofeiByBaoIds(baoIds));
    }
}
